<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="pandoc" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  <title>install_k8s_1.30.1</title>
  <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
  </style>
</head>
<body>
<h2 id="apt包管理器安装k8s1.30.1版本">apt包管理器安装K8s1.30.1版本</h2>
<h3 id="一基础配置">一、基础配置</h3>
<h4 id="关闭swap">1、关闭swap</h4>
<pre><code>sudo swapoff -a
sudo sed -i &#39;/ swap / s/^\(.*\)$/#\1/g&#39; /etc/fstab</code></pre>
<h4 id="关闭防火墙可选">2、关闭防火墙（可选）</h4>
<pre><code>sudo systemctl disable --now ufw</code></pre>
<h4 id="加载必要模块-配置内核参数">3、加载必要模块 &amp; 配置内核参数</h4>
<pre><code># 加载模块
sudo modprobe overlay
sudo modprobe br_netfilter

# 配置内核参数
cat &lt;&lt;EOF | sudo tee /etc/sysctl.d/kubernetes.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

sudo sysctl --system

# 开机自动加载 br_netfilter 内核模块
echo &quot;overlay&quot; &gt;&gt; /etc/modules-load.d/k8s.conf
echo &quot;br_netfilter&quot; | sudo tee /etc/modules-load.d/k8s.conf</code></pre>
<h3 id="二安装contained容器运行时">二、安装contained容器运行时</h3>
<pre><code># 安装依赖
sudo apt update &amp;&amp; sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release

# 安装 containerd
sudo apt install -y containerd

# 配置默认文件
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml

# 配置镜像加速器
sed -i &#39;/\[plugins.&quot;io.containerd.grpc.v1.cri&quot;.registry.mirrors\]/a\
    [plugins.&quot;io.containerd.grpc.v1.cri&quot;.registry.mirrors.&quot;docker.io&quot;]\n\
        endpoint = [&quot;https://docker.1ms.run&quot;]
&#39; /etc/containerd/config.toml


# 修改containerd的镜像源
sudo sed -i &#39;s|sandbox_image = .*|sandbox_image = &quot;registry.aliyuncs.com/google_containers/pause:3.9&quot;|&#39; /etc/containerd/config.toml


# 修改 Cgroup Driver 为 systemd
sudo sed -i &#39;s/SystemdCgroup = false/SystemdCgroup = true/&#39; /etc/containerd/config.toml

# 重启服务
sudo systemctl restart containerd &amp;&amp; sudo systemctl enable containerd</code></pre>
<h3 id="三安装-kubernetes-组件">三、安装 Kubernetes 组件</h3>
<h4 id="添加apt源">1、添加apt源</h4>
<pre><code># 创建 keyrings 目录，用于存放源的签名文件（Ubuntu 22.04 推荐做法）
sudo mkdir -p /etc/apt/keyrings

# 下载阿里云 Kubernetes 1.30 的 GPG 签名文件，并转为 APT 可识别的格式（.gpg）
curl -fsSL https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/deb/Release.key | \
  gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

# 添加 Kubernetes 1.30 的 APT 软件源到系统源列表
# signed-by= 指定只信任这个源对应的 GPG 密钥，避免信任全局
echo &quot;deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] \
https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/deb/ /&quot; | \
sudo tee /etc/apt/sources.list.d/kubernetes.list

apt update</code></pre>
<h4 id="安装k8s-1.30.1">2、安装k8s 1.30.1</h4>
<pre><code># 安装 kubelet、kubeadm、kubectl 的 1.30.1 版本
sudo apt install -y kubelet=1.30.1-1.1 kubeadm=1.30.1-1.1 kubectl=1.30.1-1.1

# 锁定版本，防止未来 apt upgrade 时被升级
sudo apt-mark hold kubelet kubeadm kubectl</code></pre>
<h3 id="四初始化集群">四、初始化集群</h3>
<h4 id="拉取镜像">1、拉取镜像</h4>
<pre><code>#拉取所需镜像

sudo kubeadm config images pull \
  --image-repository=registry.aliyuncs.com/google_containers \
  --kubernetes-version=v1.30.1</code></pre>
<h4 id="初始化集群">2、初始化集群</h4>
<pre><code># 使用默认的 containerd 和 flannel 的 pod 网段 10.244.0.0/16
# 初始化 kubeadm（将 IP 替换为你 master 节点的实际 IP）
sudo kubeadm init \
  --apiserver-advertise-address=IP \
  --image-repository=registry.aliyuncs.com/google_containers \
  --kubernetes-version=1.30.1 \
  --pod-network-cidr=10.244.0.0/16</code></pre>
<h4 id="配置kubectl">3、配置kubectl</h4>
<pre><code>mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config</code></pre>
<h4 id="其他节点加入集群">4、其他节点加入集群</h4>
<pre><code>kubeadm join 10.15.224.12:6443 --token ttwtjc.r7ef5vy8ispwe427 \
    --discovery-token-ca-cert-hash sha256:785fe1b9b8fe28e09b7387c7fb391b3f7f40963dc2333d251321ec9b934863a3</code></pre>
<h3 id="五安装网络插件大集群用calico中小集群用flannel">五、安装网络插件（大集群用calico，中、小集群用Flannel）</h3>
<pre><code>kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml</code></pre>
<h3 id="六安装ingress-nginx-v1.13">六、安装ingress-nginx v1.13</h3>
<h4 id="已经更换镜像地址">已经更换镜像地址</h4>
<pre><code>kubectl apply -f https://gitee.com/zhangjq1231/helloops/raw/master/yaml/ingress-nginx/ingress-nginx.yaml</code></pre>
</body>
</html>
